import Vue from 'vue'
import Vuex from 'vuex'
import $ from '../utils/jquery-3.4.1.min'
import router from '../router/index'
import utils from '../utils/utils'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        user: utils.getStorage('user') || {}
    },
    mutations: {
        setUser(state, user) {
            state.user = user
        }
    },
    actions: {
        loginUser(obj, user) {
            console.log(user)
            $.ajax({
                url: "http://server.hloli.cn:23300/api/login",
                dataType: "json", //返回格式为json
                data: user, //参数值
                type: "post", //请求方式
                success: function(res) {
                    if (res.code == 200) {
                        let user = res.data
                        console.log(res)
                        obj.commit('setUser', user)
                        utils.setStorage('user', user)
                    }
                }
            })
        }
    },
    modules: {

    }
})